
/**
 * @apiDefine ErrorResponse
 * @apiError (请求错误) {String} err_message 错误信息描述
 */

/**
 * @apiVersion 1.0.0
 * @apiGroup  店铺
 * @api {POST} api/store/update 更新店铺
 * @apiName api/store/update
 * @apiExample {js} axios 例子:
 *  axios.post('http://39.105.38.34:8080/api/store/update', {
 *    name: '店铺名',
 *    avatar: '店铺头像',
 *    info: '店铺简介',
 *  });
 * @apiHeader {String} authorization 用户登录或注册成功时返回的 token
 * @apiParam {String} name 店铺名
 * @apiParam {String} avatar 店铺头像
 * @apiParam {String} info 店铺简介
 * @apiSuccess (请求成功) {Object} store 店铺数据
 * @apiuse  ErrorResponse
 */

const { update } = require('../../helper/db');
const { ok, door } = require('../../helper/util');

module.exports = async ctx => {
  var params = ctx.request.body;
  var token = ctx.headers.authorization;
  await door(token);
  var store = await update('store', {
    id: params.id,
    name: params.name,
    avatar: params.avatar,
    info: params.info,
  });

  ctx.body = ok({ store });
}
